package com.tanhua.server.controller;

import com.tanhua.manage.domain.vo.ContactVo;
import com.tanhua.manage.domain.vo.MessageVo;
import com.tanhua.manage.domain.vo.PageResult;
import com.tanhua.server.service.IMService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 消息相关的操作
 */
@RestController
@RequestMapping("/messages")
public class IMController {

    @Autowired
    private IMService imService;
    /**
    * 聊一聊后的交友
    * @param paramMap
    * @return
    */
    @PostMapping("/contacts")
    public ResponseEntity makeFriends(@RequestBody Map<String , Long> paramMap){
        imService.makeFriends(paramMap.get("userId"));
        return ResponseEntity.ok(null);
    }

    /**
     * 联系人列表
     * @return
     */
    @GetMapping("/contacts")
    public ResponseEntity queryContactsList(@RequestParam(value = "page",defaultValue = "1") Long page,
                                            @RequestParam(value = "pagesize",defaultValue = "10")Long pageSize,
                                            String keyword){
        PageResult<ContactVo> pageResult = imService.queryContactsList(page,pageSize,keyword);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 谁对我点赞 分页查询
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/likes")
    public ResponseEntity likes(@RequestParam(value = "page", defaultValue = "1") Long page,
                                @RequestParam(value = "pagesize", defaultValue = "10") Long pageSize){
        //点赞的commentType=1
        PageResult<MessageVo> pageResult = imService.messageCommentList(1, page,pageSize); // 1: 点赞
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 谁对我评论 分页查询
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/comments")
    public ResponseEntity comments(@RequestParam(value = "page", defaultValue = "1") Long page,
                                   @RequestParam(value = "pagesize", defaultValue = "10") Long pageSize){
        PageResult<MessageVo> pageResult = imService.messageCommentList(2, page,pageSize); // 2: 评论
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 谁对我喜欢 分页查询
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/loves")
    public ResponseEntity loves(@RequestParam(value = "page", defaultValue = "1") Long page,
                                @RequestParam(value = "pagesize", defaultValue = "10") Long pageSize){
        PageResult<MessageVo> pageResult = imService.messageCommentList(3, page,pageSize); // 3: 喜欢
        return ResponseEntity.ok(pageResult);
    }
}
